<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #canvas {
      box-shadow: 2px 4px 6px #eee;
    }
  </style>
</head>
<body>
  <canvas id="canvas"></canvas>
</body>
<script src="/script/utils.js"></script>
<script src="/components/Ball.js"></script> 
<script>
  const canvas = document.getElementById('canvas')
  const ctx = canvas.getContext('2d')
  
  const W = canvas.width = 800
  const H = canvas.height = 600

  // let mouse = C.getOffset(canvas)

  // canvas.onclick = function () {
  //   console.log(mouse.x, mouse.y)
  // }
  const ball = new Ball({
    x: W / 2,
    y: H / 2,
    r: 35
  }).render(ctx)

  let angle = 0
  let speed = 0.02
  let rx = 200, ry = 80

  function move() {
    window.requestAnimationFrame(move)
    ctx.clearRect(0, 0, W, H)

    ctx.save()
    ctx.translate(W / 2, H / 2)
    ctx.scale(1, 0.4)
    ctx.beginPath()
    ctx.arc(0, 0, rx, 0, Math.PI * 2)
    ctx.stroke()
    ctx.restore()

    ball.x = W / 2 + rx * Math.cos(angle)
    ball.y = H / 2 + ry * Math.sin(angle)

    angle += speed
    angle %= Math.PI * 2

    ball.render(ctx)
  }

  move()
</script>
</html>